<?php

namespace think\wework\Api;

use think\wework\Abstracts\WeworkApiWithToken;

class Department extends WeworkApiWithToken
{
    private static ?Department $instance = null;
    public static function getInstance(): Department
    {
        if(!self::$instance instanceof Department) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    /**
     * 创建部门
     *
     * @param array $json
     * @return array
     */
    public function create(array $json): array
    {
        return $this->httpClient->post('department/create', compact('json'))->toArray();
    }

    /**
     * 更新部门
     *
     * @param array $json
     * @return array
     */
    public function update(array $json): array
    {
        return $this->httpClient->post('department/update', compact('json'))->toArray();
    }

    /**
     * 删除部门
     *
     * @param int $id
     * @return array
     */
    public function delete(int $id): array
    {
        $query = ['id'=>$id];
        return $this->httpClient->get('department/delete', compact('query'))->toArray();
    }

    /**
     * 获取部门列表
     *
     * @param int $id
     * @return array
     */
    public function list(int $id = 0): array
    {
        $query = $id > 0 ? ['id'=>$id] : [];
        return $this->httpClient->get('department/list', compact('query'))->toArray();
    }
}
